package com.cdz.charger.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cdz.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cdz.common.annotation.Log;
import com.cdz.common.core.controller.BaseController;
import com.cdz.common.core.domain.AjaxResult;
import com.cdz.common.enums.BusinessType;
import com.cdz.charger.domain.Pay;
import com.cdz.charger.service.IPayService;
import com.cdz.common.utils.poi.ExcelUtil;
import com.cdz.common.core.page.TableDataInfo;

/**
 * 支付Controller
 *
 * @author baefengk2
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/charger/pay" )
@Api(tags = "支付相关接口" )
public class PayController extends BaseController {
    @Autowired
    private IPayService payService;

    /**
     * 查询支付列表
     */
    @PreAuthorize("@ss.hasPermi('charger:pay:list')" )
    @GetMapping("/list" )
    @ApiOperation(value = "获取支付列表" )
    public TableDataInfo<List<Pay>> list(Pay pay) {
        startPage();
        List<Pay> list = payService.selectPayList(pay);
        return getDataTable(list);
    }

    /**
     * 导出支付列表
     */
    @PreAuthorize("@ss.hasPermi('charger:pay:export')" )
    @Log(title = "支付" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    @ApiOperation("导出支付列表" )
    public void export(HttpServletResponse response, Pay pay) {
        List<Pay> list = payService.selectPayList(pay);
        ExcelUtil<Pay> util = new ExcelUtil<Pay>(Pay. class);
        util.exportExcel(response, list, "支付数据" );
    }

    /**
     * 获取支付详细信息
     */
    @PreAuthorize("@ss.hasPermi('charger:pay:query')" )
    @GetMapping(value = "/{id}" )
    @ApiOperation("获取支付详细信息" )
    public R<Pay> getInfo(@ApiParam(value = "支付ID" , required = true)
                                   @PathVariable("id" ) Long id) {
                return R.ok(payService.selectPayById(id));
    }

    /**
     * 新增支付
     */
    @PreAuthorize("@ss.hasPermi('charger:pay:add')" )
    @Log(title = "支付" , businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增支付" )
    public AjaxResult add(@ApiParam(value = "支付实体" , required = true) @RequestBody Pay pay) {
        return toAjax(payService.insertPay(pay));
    }

    /**
     * 修改支付
     */
    @PreAuthorize("@ss.hasPermi('charger:pay:edit')" )
    @Log(title = "支付" , businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改支付" )
    public AjaxResult edit(@ApiParam(value = "支付实体" , required = true) @RequestBody Pay pay) {
        return toAjax(payService.updatePay(pay));
    }

    /**
     * 删除支付
     */
    @PreAuthorize("@ss.hasPermi('charger:pay:remove')" )
    @Log(title = "支付" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @ApiOperation("删除支付" )
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组" ) @PathVariable Long[] ids) {
        return toAjax(payService.deletePayByIds(ids));
    }


}
